package com.jianjunhuang.demo.wechatdemo;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class SignInActivity extends AppCompatActivity implements View.OnFocusChangeListener {

    private EditText nickNameEdt;
    private EditText phoneEdt;
    private EditText pwdEdt;

    private LinearLayout nickNameLL;
    private LinearLayout phoneLL;
    private LinearLayout pwdLL;

    private ImageView returnImg;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sign_in_activity);

        nickNameEdt = findViewById(R.id.sign_in_nick_name_edt);
        phoneEdt = findViewById(R.id.sign_in_phone_edt);
        pwdEdt = findViewById(R.id.sign_in_pwd_edt);

        nickNameLL = findViewById(R.id.sign_in_nick_name_ll);
        phoneLL = findViewById(R.id.sign_in_phone_ll);
        pwdLL = findViewById(R.id.sign_in_pwd_ll);

        returnImg = findViewById(R.id.sign_in_return_img);
        returnImg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        nickNameEdt.setOnFocusChangeListener(this);
        phoneEdt.setOnFocusChangeListener(this);
        pwdEdt.setOnFocusChangeListener(this);
    }

    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        switch (v.getId()) {
            case R.id.sign_in_nick_name_edt: {
                if (hasFocus) {
                    nickNameLL.setBackgroundResource(R.drawable.input_focus_drawable);
                } else {
                    nickNameLL.setBackgroundResource(R.drawable.input_not_focus_drawable);
                }
                break;
            }
            case R.id.sign_in_phone_edt: {
                if (hasFocus) {
                    phoneLL.setBackgroundResource(R.drawable.input_focus_drawable);
                } else {
                    phoneLL.setBackgroundResource(R.drawable.input_not_focus_drawable);
                }
                break;
            }
            case R.id.sign_in_pwd_edt: {
                if (hasFocus) {
                    pwdLL.setBackgroundResource(R.drawable.input_focus_drawable);
                } else {
                    pwdLL.setBackgroundResource(R.drawable.input_not_focus_drawable);
                }
                break;
            }
        }
    }

    private static final String TAG = "SignInActivity";
}
